package com.xx.xunyou.serviceImpl;

import com.xx.xunyou.dao.item.xiaochenggushiduo.XiaochenggushiduoContentDAO;
import com.xx.xunyou.dao.item.xiaochenggushiduo.XiaochenggushiduoDAO;
import com.xx.xunyou.entity.item.chizhuzaixiang.ChizhuzaixiangContent;
import com.xx.xunyou.entity.item.chizhuzaixiang.vo.ChizhuzaixiangVo;
import com.xx.xunyou.entity.item.xiaochenggushiduo.Xiaochenggushiduo;
import com.xx.xunyou.entity.item.xiaochenggushiduo.XiaochenggushiduoContent;
import com.xx.xunyou.entity.item.xiaochenggushiduo.vo.XiaochenggushiduoVo;
import com.xx.xunyou.service.XiaochenggushiduoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author: zhl
 * @Description:
 */
@Service
public class XiaochenggushiduoServiceImpl implements XiaochenggushiduoService {

    @Autowired
    private XiaochenggushiduoDAO xiaochenggushiduoDAO;

    @Autowired
    private XiaochenggushiduoContentDAO xiaochenggushiduoContentDAO;

    @Override
    public Integer queryListCountToManager(Map<String, Object> map) {
        return xiaochenggushiduoDAO.queryListCountToManager(map);
    }

    @Override
    public List<Map> queryListToManager(Map<String, Object> map) {
        return xiaochenggushiduoDAO.queryListToManager(map);
    }

    @Override
    @Transactional
    public void insert(Xiaochenggushiduo xiaochenggushiduo, String content) {
        Date date = new Date();
        xiaochenggushiduo.setCreateTime(date);
        xiaochenggushiduoDAO.insertBackId(xiaochenggushiduo);
        //内容
        XiaochenggushiduoContent xiaochenggushiduoContent = new XiaochenggushiduoContent();
        xiaochenggushiduoContent.setXiaochenggushiduoId(xiaochenggushiduo.getXiaochenggushiduoId());
        xiaochenggushiduoContent.setContent(content);
        xiaochenggushiduoContent.setCreateTime(date);
        xiaochenggushiduoContentDAO.insert(xiaochenggushiduoContent);
    }

    @Override
    public Xiaochenggushiduo queryByIdToManager(Integer xiaochenggushiduoId) {
        return xiaochenggushiduoDAO.selectByPrimaryKey(xiaochenggushiduoId);
    }

    @Override
    public XiaochenggushiduoContent queryContentByIdToManager(Integer xiaochenggushiduoId) {
        return xiaochenggushiduoContentDAO.selectByPrimaryKey(xiaochenggushiduoId);
    }

    @Override
    @Transactional
    public void update(Xiaochenggushiduo xiaochenggushiduo, String content) {
        xiaochenggushiduoDAO.updateByPrimaryKeySelective(xiaochenggushiduo);
        //内容
        XiaochenggushiduoContent xiaochenggushiduoContent = new XiaochenggushiduoContent();
        xiaochenggushiduoContent.setXiaochenggushiduoId(xiaochenggushiduo.getXiaochenggushiduoId());
        xiaochenggushiduoContent.setContent(content);
        xiaochenggushiduoContentDAO.updateByPrimaryKeySelective(xiaochenggushiduoContent);
    }

    @Override
    @Transactional
    public void delete(Integer xiaochenggushiduoId) {
        xiaochenggushiduoDAO.deleteByPrimaryKey(xiaochenggushiduoId);
        xiaochenggushiduoContentDAO.deleteByPrimaryKey(xiaochenggushiduoId);
    }

    @Override
    @Transactional
    public void recommend(Integer xiaochenggushiduoId) {
        xiaochenggushiduoDAO.recommend(xiaochenggushiduoId,new Date());
    }

    @Override
    @Transactional
    public void notRecommend(Integer xiaochenggushiduoId) {
        xiaochenggushiduoDAO.notRecommend(xiaochenggushiduoId);
    }

    @Override
    public List<XiaochenggushiduoVo> queryListToAPPIndex(Map<String, Object> map) {
        return xiaochenggushiduoDAO.queryListToAPPIndex(map);
    }
}
